package com.dji.custom.service.impl;

import com.dji.custom.dao.IExpandMediaFileMapper;
import com.dji.custom.model.entity.ExpandMediaFileEntity;
import com.dji.custom.service.IExpandMediaFileService;
import com.dji.custom.service.PythonCustomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 媒体文件拓展Service业务层处理
 *
 * @author ruoyi
 * @date 2023-11-07
 */
@Service
public class ExpandMediaFileServiceImpl implements IExpandMediaFileService
{
    @Autowired
    private IExpandMediaFileMapper expandMediaFileMapper;

    @Autowired
    private PythonCustomService pythonService;

    private static String mediaUrl = "http://111.35.143.112:8077/live/";

    @Override
    public int insertExpandMediaCustom(String liveUrlStream, String rtmpUrl, String deviceSn, String deviceName,
                                       String jobId, String waylineId) {
        // 调用python开启识别
        pythonService.startPythonAi(jobId, rtmpUrl, waylineId, deviceSn, deviceName);
        // 录像文件地址
        long nowTimeLong=Long.parseLong(liveUrlStream);
        Date nowDate = new Date(nowTimeLong);
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
        String dataStr = sdf1.format(nowDate);
        String filePath = mediaUrl + liveUrlStream+"/"+dataStr;
        //保存媒体文件
        ExpandMediaFileEntity expandMediaFileInsert = new ExpandMediaFileEntity(1L, waylineId, jobId, deviceSn
                , deviceName, liveUrlStream + ".mp4", filePath, filePath);
        return expandMediaFileMapper.insert(expandMediaFileInsert);
    }




}
